package com.example.myblog01.dao;

import com.example.myblog01.pojo.Blog;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface BlogServiceDao extends JpaRepository<Blog ,Long>, JpaSpecificationExecutor<Blog> {
//JpaSpecificationExecutor<Blog>高级的混合查询 类

//    查询是否推荐的博客
    @Query("select b from Blog b where b.recommend=true")
    List<Blog> findTop(Pageable pageable);

//     ?1代表第一个参数 query
    @Query("select b from Blog b where b.title like ?1 or b.content like ?1")
    Page<Blog> findByQuery(String query, Pageable pageable);



    @Query("select function('date_format',b.updateTime,'%Y') as year from Blog b group by function('date_format',b.updateTime,'%Y') order by year")
    List<String> findGroupYear();

    @Query("select b from  Blog b where function('date_format',b.updateTime,'%Y') = ?1")
    List<Blog> findByYear(String year);
}
